/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package com.lifesting.wfs.model.impl;

import com.lifesting.wfs.model.AutoNode;
import com.lifesting.wfs.model.Decision;
import com.lifesting.wfs.model.End;
import com.lifesting.wfs.model.Fork;
import com.lifesting.wfs.model.Join;
import com.lifesting.wfs.model.ModelPackage;
import com.lifesting.wfs.model.Node;
import com.lifesting.wfs.model.ProcessDefinition;
import com.lifesting.wfs.model.Start;

import com.lifesting.wfs.model.TaskNode;
import java.util.Collection;

import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.common.util.EList;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.util.BasicFeatureMap;
import org.eclipse.emf.ecore.util.FeatureMap;
import org.eclipse.emf.ecore.util.EObjectContainmentEList;
import org.eclipse.emf.ecore.util.InternalEList;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Process Definition</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link com.lifesting.wfs.model.impl.ProcessDefinitionImpl#getStart <em>Start</em>}</li>
 *   <li>{@link com.lifesting.wfs.model.impl.ProcessDefinitionImpl#getEnd <em>End</em>}</li>
 *   <li>{@link com.lifesting.wfs.model.impl.ProcessDefinitionImpl#getAllNodes <em>All Nodes</em>}</li>
 *   <li>{@link com.lifesting.wfs.model.impl.ProcessDefinitionImpl#getJoins <em>Joins</em>}</li>
 *   <li>{@link com.lifesting.wfs.model.impl.ProcessDefinitionImpl#getForks <em>Forks</em>}</li>
 *   <li>{@link com.lifesting.wfs.model.impl.ProcessDefinitionImpl#getDecisions <em>Decisions</em>}</li>
 *   <li>{@link com.lifesting.wfs.model.impl.ProcessDefinitionImpl#getTaskNodes <em>Task Nodes</em>}</li>
 *   <li>{@link com.lifesting.wfs.model.impl.ProcessDefinitionImpl#getAutoNodes <em>Auto Nodes</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class ProcessDefinitionImpl extends GraphElementsImpl implements ProcessDefinition {
	/**
	 * The cached value of the '{@link #getAllNodes() <em>All Nodes</em>}' attribute list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getAllNodes()
	 * @generated
	 * @ordered
	 */
	protected FeatureMap allNodes;
	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected ProcessDefinitionImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return ModelPackage.Literals.PROCESS_DEFINITION;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Start getStart() {
		Start start = basicGetStart();
		return start != null && start.eIsProxy() ? (Start)eResolveProxy((InternalEObject)start) : start;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Start basicGetStart() {
		return (Start)getAllNodes().get(ModelPackage.Literals.PROCESS_DEFINITION__START, false);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public End getEnd() {
		End end = basicGetEnd();
		return end != null && end.eIsProxy() ? (End)eResolveProxy((InternalEObject)end) : end;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public End basicGetEnd() {
		return (End)getAllNodes().get(ModelPackage.Literals.PROCESS_DEFINITION__END, false);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public FeatureMap getAllNodes() {
		if (allNodes == null) {
			allNodes = new BasicFeatureMap(this, ModelPackage.PROCESS_DEFINITION__ALL_NODES);
		}
		return allNodes;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<Join> getJoins() {
		return getAllNodes().list(ModelPackage.Literals.PROCESS_DEFINITION__JOINS);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<Fork> getForks() {
		return getAllNodes().list(ModelPackage.Literals.PROCESS_DEFINITION__FORKS);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<Decision> getDecisions() {
		return getAllNodes().list(ModelPackage.Literals.PROCESS_DEFINITION__DECISIONS);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public TaskNode getTaskNodes() {
		TaskNode taskNodes = basicGetTaskNodes();
		return taskNodes != null && taskNodes.eIsProxy() ? (TaskNode)eResolveProxy((InternalEObject)taskNodes) : taskNodes;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public TaskNode basicGetTaskNodes() {
		return (TaskNode)getAllNodes().get(ModelPackage.Literals.PROCESS_DEFINITION__TASK_NODES, false);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setTaskNodes(TaskNode newTaskNodes) {
		((FeatureMap.Internal)getAllNodes()).set(ModelPackage.Literals.PROCESS_DEFINITION__TASK_NODES, newTaskNodes);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<AutoNode> getAutoNodes() {
		return getAllNodes().list(ModelPackage.Literals.PROCESS_DEFINITION__AUTO_NODES);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case ModelPackage.PROCESS_DEFINITION__ALL_NODES:
				return ((InternalEList<?>)getAllNodes()).basicRemove(otherEnd, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case ModelPackage.PROCESS_DEFINITION__START:
				if (resolve) return getStart();
				return basicGetStart();
			case ModelPackage.PROCESS_DEFINITION__END:
				if (resolve) return getEnd();
				return basicGetEnd();
			case ModelPackage.PROCESS_DEFINITION__ALL_NODES:
				if (coreType) return getAllNodes();
				return ((FeatureMap.Internal)getAllNodes()).getWrapper();
			case ModelPackage.PROCESS_DEFINITION__JOINS:
				return getJoins();
			case ModelPackage.PROCESS_DEFINITION__FORKS:
				return getForks();
			case ModelPackage.PROCESS_DEFINITION__DECISIONS:
				return getDecisions();
			case ModelPackage.PROCESS_DEFINITION__TASK_NODES:
				if (resolve) return getTaskNodes();
				return basicGetTaskNodes();
			case ModelPackage.PROCESS_DEFINITION__AUTO_NODES:
				return getAutoNodes();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case ModelPackage.PROCESS_DEFINITION__ALL_NODES:
				((FeatureMap.Internal)getAllNodes()).set(newValue);
				return;
			case ModelPackage.PROCESS_DEFINITION__JOINS:
				getJoins().clear();
				getJoins().addAll((Collection<? extends Join>)newValue);
				return;
			case ModelPackage.PROCESS_DEFINITION__FORKS:
				getForks().clear();
				getForks().addAll((Collection<? extends Fork>)newValue);
				return;
			case ModelPackage.PROCESS_DEFINITION__DECISIONS:
				getDecisions().clear();
				getDecisions().addAll((Collection<? extends Decision>)newValue);
				return;
			case ModelPackage.PROCESS_DEFINITION__TASK_NODES:
				setTaskNodes((TaskNode)newValue);
				return;
			case ModelPackage.PROCESS_DEFINITION__AUTO_NODES:
				getAutoNodes().clear();
				getAutoNodes().addAll((Collection<? extends AutoNode>)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case ModelPackage.PROCESS_DEFINITION__ALL_NODES:
				getAllNodes().clear();
				return;
			case ModelPackage.PROCESS_DEFINITION__JOINS:
				getJoins().clear();
				return;
			case ModelPackage.PROCESS_DEFINITION__FORKS:
				getForks().clear();
				return;
			case ModelPackage.PROCESS_DEFINITION__DECISIONS:
				getDecisions().clear();
				return;
			case ModelPackage.PROCESS_DEFINITION__TASK_NODES:
				setTaskNodes((TaskNode)null);
				return;
			case ModelPackage.PROCESS_DEFINITION__AUTO_NODES:
				getAutoNodes().clear();
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case ModelPackage.PROCESS_DEFINITION__START:
				return basicGetStart() != null;
			case ModelPackage.PROCESS_DEFINITION__END:
				return basicGetEnd() != null;
			case ModelPackage.PROCESS_DEFINITION__ALL_NODES:
				return allNodes != null && !allNodes.isEmpty();
			case ModelPackage.PROCESS_DEFINITION__JOINS:
				return !getJoins().isEmpty();
			case ModelPackage.PROCESS_DEFINITION__FORKS:
				return !getForks().isEmpty();
			case ModelPackage.PROCESS_DEFINITION__DECISIONS:
				return !getDecisions().isEmpty();
			case ModelPackage.PROCESS_DEFINITION__TASK_NODES:
				return basicGetTaskNodes() != null;
			case ModelPackage.PROCESS_DEFINITION__AUTO_NODES:
				return !getAutoNodes().isEmpty();
		}
		return super.eIsSet(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public String toString() {
		if (eIsProxy()) return super.toString();

		StringBuffer result = new StringBuffer(super.toString());
		result.append(" (allNodes: ");
		result.append(allNodes);
		result.append(')');
		return result.toString();
	}

} //ProcessDefinitionImpl
